package com.seckill.search.repository;

import com.seckill.search.domain.po.Item;

import java.util.List;
import java.util.Optional;

public interface ItemRepository {
    String INDEX_NAME = "Item";
    String DEFAULT_QUERY_NAME = "name";
    String CATEGORY_ID_LV1 = "firstCateId";
    String CATEGORY_ID_LV2 = "secondCateId";
    String CATEGORY_ID_LV3 = "thirdCateId";
    String PUBLISH_TIME = "publishTime";
    String FREE = "free";
    String STATUS = "status";
    String TYPE = "type";
    String UPDATE_TIME = "updateTime";
    String SOLD = "sold";

    /**
     * <h1>更新sold的脚本</h1>
     * <pre>
     * {
     *   "script": {
     *     "lang": "painless",
     *     "source": "ctx._source.sold += params.count"
     *   }
     * }
     * </pre>
     */
    String INCREMENT_SOLD_SCRIPT_ID = "increment_sold";
    String INCREMENT_SOLD_SCRIPT_PARAM = "count";

    void save(Item Item);

    void deleteById(Long ItemId);

    Optional<Item> findById(Long ItemId);

    void updateById(Long ItemId, Object ... docs);

    void increment(Long ItemId, String field, int amount);

    void incrementSold(List<Long> ItemIds, int amount);

    void saveAll(List<Item> list);

    void deleteByIds(List<Long> ItemIds);
}

/*
PUT /Item
{
    "mappings": {
    "properties": {
        "id": {
            "type": "long"
        },
        "name": {
            "type": "text",
            "analyzer": "ik_smart"
        },
        "firstCateId": {
            "type": "long"
        },
        "secondCateId": {
            "type": "long"
        },
        "thirdCateId": {
            "type": "long"
        },
        "sold": {
            "type": "integer"
        },
        "price": {
            "type": "integer"
        },
        "iamge": {
            "type": "text"
        }
    }
}
}
*/